package com.qyhl.school.school.home.newhome;

import android.annotation.SuppressLint;
import android.content.Context;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.qyhl.school.R;
import com.qyhl.webtv.commonlib.entity.school.SchoolVlogBean;

import java.util.List;

public class CoverFlowAdapter extends RecyclerView.Adapter<CoverFlowAdapter.ViewHolder> {
    private Context mContext;
    private onItemClick clickCb;
    private List<SchoolVlogBean> mListBean;

    public void setListBean(List<SchoolVlogBean> mListBean) {
        this.mListBean = mListBean;
    }

    public CoverFlowAdapter(Context c) {
        mContext = c;
    }

    public CoverFlowAdapter(Context c, onItemClick cb) {
        mContext = c;
        clickCb = cb;
    }

    public void setOnClickListener(onItemClick cb) {
        this.clickCb = cb;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View v = LayoutInflater.from(mContext).inflate(R.layout.item_school_new_home_vlog, viewGroup, false);
        return new ViewHolder(v);
    }

    @Override
    @SuppressLint("RecyclerView")
    public void onBindViewHolder(ViewHolder viewHolder, final int position) {
        Glide.with(mContext)
                .load(mListBean.get(position).getLogo())
                .apply(new RequestOptions().error(R.drawable.cover_large_default).placeholder(R.drawable.cover_large_default))
                .into(viewHolder.cover);

        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (clickCb != null) {
                    clickCb.clickItem(position);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return mListBean == null ? 0 : mListBean.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        ImageView cover;
        TextView title;

        public ViewHolder(View itemView) {
            super(itemView);
            cover = itemView.findViewById(R.id.cover);
            title = itemView.findViewById(R.id.title);
        }
    }

    interface onItemClick {
        void clickItem(int pos);
    }
}
